define(function (require) {
    var app = require('/../js/app');
    require('ui-table');
    //require('angular-datepicker');


    app.useModule("ui.table");
    //app.useModule("datePicker");
    var datepicker = require('datepicker');
    var toastr=require('toastr');


    app.controller('excel_individualCtrl', ['$scope','$http','$filter',function ($scope, $http,$filter){


        datepicker($scope);
        $scope.condition={};


        $scope.select2Options = {
            minimumResultsForSearch: Infinity,//不出现搜索框
            placeholder:"请选择所属机构",
        };




        $scope.selectOptions = {
            minimumResultsForSearch: Infinity,//不出现搜索框
            placeholder:"请选择员工",
        };

        $scope.condition.queryDateX=new Date();
        $scope.date1=new Date();
        $scope.date=$filter('date')($scope.date1,'yyyy-MM-dd');


        $scope.orderParams = {
            url: "/admin/report/listPersonalResult",
            ajax:{queryDate:$scope.date}

        };

        //导出
        $scope.download=function(){

            var params={};
            params=$scope.condition;
            $http.post("/admin/report/excelPersonalResult",params)
                .success(function (data){
                    console.log(data)
                    if(data.result=="success"){
                        window.open(data.file);
                    }else{
                        toastr.error("导出失败");
                    }
                }).error(function(data){
                });
        };
        //公司列表
        $scope.getCompanyList=function(){
            $scope.companise={};
            $scope.idstr='';
            $http({
                method: 'POST',
                url: "/admin/report/listCompany",
                data:{}
            }).success(function(data) {
                console.log(data)
                $scope.companise=data;
                for(var i=0;i<data.length;i++){
                    $scope.idstr+=data[i].id+','
                }
                $scope.idstr=$scope.idstr.substring(0,$scope.idstr.length-1);
            }).error(function() {
            });
        };
        $scope.getCompanyList();
        //业务员列表
        $scope.getManList=function(id){
            //var str='';
            //for(var i=0;i<id.length;i++){
            //    str+=id[i]+','
            //}

            $scope.man={};
            $http({
                method: 'POST',
                url: "/admin/report/listSaleman",
                data:{companyId:id}
            }).success(function(data) {
                console.log(data)
                $scope.man=data;
            }).error(function() {
            });
        };


        //搜索
        $scope.search = function() {
            $scope.condition.queryDate=$scope.condition.queryDateX;
            $scope.condition.queryDate=$filter('date')($scope.condition.queryDate,'yyyy-MM-dd');
            $scope.orderParams.ajaxParam=$scope.condition;
            $scope.orderParams.reload();
        };

        //搜索重置
        $scope.reset=function(){
            $scope.condition = {};
            $scope.search();

        };


    }]);


});